using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;

using System.Diagnostics;

namespace WXWorkSvc.Common.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
    public string? RequestId { get; set; }

    public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
    public string? ErrorMessage { get; set; }


   
    public void OnGet()
    {
        RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

        var exception = Request.HttpContext.Features.Get<IExceptionHandlerFeature>();
        if (exception != null)
        {
            ErrorMessage = exception.Error.Message + exception.Error.InnerException?.Message;

        }
    }
    public void OnPost()
    {
        RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;

        var exception = Request.HttpContext.Features.Get<IExceptionHandlerFeature>();
        if (exception != null)
        {
            ErrorMessage = exception.Error.Message + exception.Error.InnerException?.Message;

        }
    }
}
